<template lang="html">
  <div class="global">

  </div>
</template>

<script>
import api from '@/utils/api'
import ZanTab from 'mpvue-zanui/src/components/zan/tab'
import store from '@/store/store'
import utils from '@/utils/index'
export default {
  data () {
    return {
      districtId: 0,
      tab1: {
        list: [],
        scroll: true,
        selectedId: 0
      }
    }
  },
  // vuex获取状态参数
  computed: {
    cookie () {
      return store.state.cookie
    }
  },
  // 获取上个页面传过来的参数
  onLoad () {
    this.districtId = this.$root.$mp.query.districtId
  },
  methods: {
    // zan组件切换tab
    ...ZanTab.methods,
    handleZanTabChange (e) {
      const {componentId, selectedId} = e
      this[componentId].selectedId = selectedId
    },
    // 跳转到其他页面，并传递参数
    toAnotherPage () {
      this.$router.push({ path: '', query: { districtId: this.districtId } })
    },
    // 调用接口
    oppropertymanagelist (districtId) {
      var param = {}
      param['district_id'] = districtId
      const oppropertymanagelist = api.oppropertymanagelist(param)
      oppropertymanagelist.then(d => {
        if (d.code === 200) {
          this.paramName = d.data.parmName
        }
      })
      .catch((e) => {
        console.log(e)
      })
    },
    // 上传图片
    toPicker (index) {
      var _this = this
      wx.chooseImage({
        count: 3, // 默认9
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function (res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          var tempFilePaths = res.tempFilePaths
          wx.uploadFile({
            url: _this.url + 'apii/user/opupload',
            filePath: tempFilePaths[0],
            name: 'img[0]',
            formData: {
              'name': 'img[0]'
            },
            header: {
              'Content-Type': 'multipart/form-data',
              'Cookie': _this.cookie
            },
            success: function (res) {
              // console.log(res)
              var data = JSON.parse(res.data)
              _this.imgList[index] = data.data[0]
              _this.images[index] = utils.find(data.data[0], '/', 2)
              if (index === _this.imgList.length - 1) {
                _this.imgList.push('http://fanglilai-pic.oss-cn-shenzhen.aliyuncs.com/mw690/20180521/2018052102375512648.jpg')
              }
            },
            fail: function (res) {
            }
          })
        }
      })
    },
    // 获取地址和经纬度
    getLocation () {
      var _this = this
      wx.chooseLocation({
        success: function (res) {
          _this.address = res.address
          _this.latitude = res.latitude
          _this.longitude = res.longitude
          _this.latlng = '' + _this.latitude + ',' + _this.longitude
        }
      })
    },
    // 根据经纬度转换为省市id
    geocoder (latlng) {
      const geocoder = api.geocoder(latlng)
      geocoder.then(d => {
        this.provinceId = d.result.addressComponent.adcode.substr(0, 2) + '0000'
        this.cityId = d.result.addressComponent.adcode.substr(0, 4) + '00'
        this.regionId = d.result.addressComponent.adcode
      })
      .catch((e) => {
        console.log(e)
      })
    },

    usefulMethods () {
      // vuex上传状态参数
      store.commit('setAddress', this.address)
      // 弹框提示
      wx.showToast({
        title: '删除成功',
        icon: 'success'
      })
    }
  }
}
</script>

<style lang="css">
  @import "./template.css";
</style>
